# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: http://doc.scrapy.org/en/latest/topics/item-pipeline.html

import MySQLdb

# class MoviePipeline(object):
#     def process_item(self, item, spider):
#         return item


class Movie2Pipeline(object):
    def process_item(self, item, spider):
        conn = MySQLdb.connect(host="192.168.0.59", user="root", passwd="123123", db='scrapy', charset="utf8")
        cursor = conn.cursor()
        try:
            cursor.execute("insert into films(movie_name, movie_img_url, movie_info, movie_download_url) values('%s', '%s', '%s', '%s')" % (item['movie_name'], item['movie_img_url'], item['movie_info'], item['movie_download_url']))
            conn.commit()
        except Exception as e:
            print(e)
        finally:
            conn.close()
